import java.util.concurrent.*;

/**
 * @ClassName test
 * @Description TODO
 * @Author hongjun
 * @Date 2023/10/31 12:05
 * @Version 1.0
 */
public class test {
    interface DeviceProviderRegistry {
        DeviceProvider getProviderService(String deviceId);
    }

    interface DeviceProvider {
        void sendCommand(String command);
    }

    interface DeviceCommandService {
        void sendCommand(String deviceId, String command);
    }

    public class DeviceCommandServiceImpl implements DeviceCommandService {
        private DeviceProviderRegistry registry;

        //多线程任务队列
        private final ExecutorService fixed;

        public DeviceCommandServiceImpl() {
            fixed = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),//核心线程数
                    100,
                    0L,
                    TimeUnit.MILLISECONDS,
                    new LinkedBlockingDeque<Runnable>());
        }

        @Override
        public void sendCommand(String deviceId, String command) {
                Future<?> submit = fixed.submit(() -> {
                    DeviceProvider provider = registry.getProviderService(deviceId);
                    provider.sendCommand(command);

                });
                boolean done = submit.isDone();
                //log.info(String.format("执行完成 done%s,deviceId%s,command%s", done, deviceId, command));
            }

    }
}
